//
//  SRSchoolClassServices.m
//  StoryShow
//
//  Created by CyonLeuMBP on 2017/7/20.
//  Copyright © 2017年 qudiandu.cn. All rights reserved.
//

#import "SRSchoolClassServices.h"

#import "SRWorkListItemModel.h"
#import "SRSchoolClassListModel.h"
#import "SRClassMemberItemModel.h"
#import "SRHomeworkFinishItemModel.h"

#import "SRHomeworkDetailItemModel.h"

@implementation SRSchoolClassServices

/*
 *  查询作品列表
 */
+ (void)queryWorkListPage:(NSInteger)page groupID:(NSString *)groupID userType:(SRSchoolClassUserType)userType successBlock:(FZSuccessBlock)successBlock failureBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = nil;
    if (userType == SRSchoolClassUserTypeTeacher) {
        urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_teachTaskList"];
    } else {
        urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_userTaskList"];
    }
    
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:@(page) forKey:@"start"];
    [params setValue:@(20) forKey:@"rows"];
    [params setValue:groupID forKey:@"group_id"];
    
    [manager GET:urlString needCache:NO parameters:params responseClass:[SRWorkListItemModel class] success:successBlock failure:failureBlock];
}

/*
 *  查询班级列表
 */
+ (void)queryClassListUserType:(SRSchoolClassUserType)userType successBlock:(FZSuccessBlock)successBlock failureBlock:(FZFailureBlock)failureBlock{
    NSString *urlString = nil;
    if (userType == SRSchoolClassUserTypeTeacher) {
        urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_teacherGroup"];
    } else {
        urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_userGroup"];
    }
    
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:@(0) forKey:@"start"];
//    [params setValue:@(50) forKey:@"rows"];
    
    [manager GET:urlString needCache:NO parameters:params responseClass:[SRSchoolClassListModel class] success:successBlock failure:failureBlock];
}


/*
 *  查询班级详情
 */
+ (void)queryClassDetailGroupID:(NSString *)groupID successBlock:(FZSuccessBlock)successBlock failureBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_detail"];
    
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:groupID forKey:@"group_id"];
    
    [manager GET:urlString needCache:NO parameters:params responseClass:[SRSchoolClassListModel class] success:successBlock failure:failureBlock];
}


/*
 *  查询班级成员列表
 */
+ (void)queryClassMemberListPage:(NSInteger)page groupID:(NSString *)groupID successBlock:(FZSuccessBlock)successBlock failureBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_memberList"];

    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
//    [params setValue:@(page) forKey:@"start"];
//    [params setValue:@(20) forKey:@"rows"];
    [params setValue:groupID forKey:@"group_id"];
    
    [manager GET:urlString needCache:NO parameters:params responseClass:[SRClassMemberItemModel class] success:successBlock failure:failureBlock];
}


/*
 *  删除班级成员
 */
+ (void)deleteClassMemberGroupID:(NSString *)groupID delUIDs:(NSString *)uids successBlock:(FZSuccessBlock)successBlock failureBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_memberDel"];
    
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:uids forKey:@"del_uid"];
    [params setValue:groupID forKey:@"group_id"];
    
    [manager POST:urlString needCache:NO parameters:params responseClass:nil success:successBlock failure:failureBlock];
}


/*
 *  添加班级任务
 */
+ (void)addTaskGroupID:(NSString *)groupID bookID:(NSString *)bookID catalogueID:(NSString *)catalogueID successBlock:(FZSuccessBlock)successBlock failureBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_taskAdd"];
    
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:bookID forKey:@"book_id"];
    [params setValue:groupID forKey:@"group_id"];
    [params setValue:catalogueID forKey:@"catalogue_id"];

    [manager POST:urlString needCache:NO parameters:params responseClass:nil success:successBlock failure:failureBlock];
}

/*
 *  删除任务
 */
+ (void)deleteTaskGroupID:(NSString *)groupID taskID:(NSString *)taskID successBlock:(FZSuccessBlock)successBlock failureBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_delTask"];
    
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:taskID forKey:@"task_id"];
    [params setValue:groupID forKey:@"group_id"];
    
    [manager POST:urlString needCache:NO parameters:params responseClass:nil success:successBlock failure:failureBlock];
}

/*
 * 老师端任务完成列表
 */
+ (void)queryTaskFinishListGroupID:(NSString *)groupID taskID:(NSString *)taskID type:(SRClassHomeworkType)type successBlock:(FZSuccessBlock)successBlock failureBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = nil;
    if (type == SRClassHomeworkTypeDubbing) {
       urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_taskFinishList"];
    } else {
        urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_problemFinishList"];

    }
    
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:taskID forKey:@"task_id"];
    [params setValue:groupID forKey:@"group_id"];
    
    [manager GET:urlString needCache:NO parameters:params responseClass:[SRWorkListItemModel class] success:successBlock failure:failureBlock];
}

/*
 * 老师端题库完成列表
 */
+ (void)queryQuestionFinishListGroupID:(NSString *)groupID taskID:(NSString *)taskID successBlock:(FZSuccessBlock)successBlock failureBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_problemFinishList"];
    
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:taskID forKey:@"task_id"];
    [params setValue:groupID forKey:@"group_id"];
    
    [manager GET:urlString needCache:NO parameters:params responseClass:[SRWorkListItemModel class] success:successBlock failure:failureBlock];
}

/*
 *  作业点评
 */
+ (void)addShowCommentShowID:(NSString *)showID comment:(NSString *)comment type:(SRClassHomeworkType)type finishID:(NSString *)finishID successBlock:(FZSuccessBlock)successBlock failureBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_showComment"];
    
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:showID forKey:@"show_id"];
    [params setValue:comment forKey:@"comment"];
    [params setValue:@(type) forKey:@"ctype"];
    [params setValue:finishID forKey:@"problem_finish_id"];
    
    [manager POST:urlString needCache:NO parameters:params responseClass:nil success:successBlock failure:failureBlock];
}

/*
 *  作业点评
 */
+ (void)addHomeworkCommentWithParams:(NSDictionary *)params successBlock:(FZSuccessBlock)successBlock failureBlock:(FZFailureBlock)failureBlock {
	NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_showComment"];
	
	SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
	[manager POST:urlString needCache:NO parameters:params responseClass:nil success:successBlock failure:failureBlock];
}


/*
 *  催作业
 */
+ (void)TaskRemindGroupID:(NSString *)groupID taskID:(NSString *)taskID successBlock:(FZSuccessBlock)successBlock failureBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_taskRemind"];
    
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:taskID forKey:@"task_id"];
    [params setValue:groupID forKey:@"group_id"];
    
    [manager POST:urlString needCache:NO parameters:params responseClass:nil success:successBlock failure:failureBlock];
}

/*
 *  创建班级
 */
+ (void)createClassWithSchoolName:(NSString *)school_name grade:(NSString *)grade className:(NSString *)className phone:(NSString *)telephone  successBlock:(FZSuccessBlock)successBlock failureBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_add"];
    
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:school_name forKey:@"school_name"];
    [params setValue:grade forKey:@"grade"];
    [params setValue:className forKey:@"class_name"];
    [params setValue:telephone forKey:@"telephone"];
    
    [manager POST:urlString needCache:NO parameters:params responseClass:nil success:successBlock failure:failureBlock];
}


/*
 *  创建班级
 */
+ (void)addClassWithNickname:(NSString *)nickname code:(NSString *)code successBlock:(FZSuccessBlock)successBlock failureBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_memberAdd"];
    
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:nickname forKey:@"nickname"];
    [params setValue:code forKey:@"code"];
    
    [manager POST:urlString needCache:NO parameters:params responseClass:nil success:successBlock failure:failureBlock];
}

/*
 *  查询消息红点
 */
+ (void)queryLatestMessageSuccessBlock:(FZSuccessBlock)successBlock failureBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"basic_messageRemind"];
    
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    [manager GET:urlString needCache:NO parameters:nil responseClass:nil success:successBlock failure:failureBlock];
}

#pragma mark - Task Question List

/*
 *  题库任务详情
 */
+ (void)queryProblemDetailWithTaskID:(NSString *)taskID SuccessBlock:(FZSuccessBlock)successBlock failureBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_taskProblemDetail"];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:taskID forKey:@"task_id"];
    
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    [manager GET:urlString needCache:NO parameters:params responseClass:[SRHomeworkDetailItemModel class] success:successBlock failure:failureBlock];
}

/*
 *  题库任务完成详情
 */
+ (void)queryProblemFinishDetailWithFinishID:(NSString *)finishID SuccessBlock:(FZSuccessBlock)successBlock failureBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_problemFinishDetail"];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:finishID forKey:@"finish_id"];
    
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    [manager GET:urlString needCache:NO parameters:params responseClass:[SRHomeworkDetailItemModel class] success:successBlock failure:failureBlock];
}

/*
 *  题库任务提交
 */
+ (void)submitProblemAnswerWithTaskID:(NSString *)taskID
                              groupID:(NSString *)groupID
                               answer:(NSString *)answer
                         SuccessBlock:(FZSuccessBlock)successBlock
                         failureBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_taskProblemFinish"];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:taskID forKey:@"task_id"];
    [params setValue:groupID forKey:@"group_id"];
    [params setValue:answer forKey:@"answer"];
    
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    [manager POST:urlString needCache:NO parameters:params responseClass:nil success:successBlock failure:failureBlock];
}

/*
 *  题库任务详情
 */
+ (void)queryProblemDetailWithFinishID:(NSString *)finish_id SuccessBlock:(FZSuccessBlock)successBlock failureBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"group_taskProblemDetail"];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:finish_id forKey:@"finish_id"];
    
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    [manager GET:urlString needCache:NO parameters:params responseClass:[SRHomeworkDetailItemModel class] success:successBlock failure:failureBlock];
}


@end
